package com.example.restaurantclient.Adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.restaurantclient.ConfigUtil.CircleImageUtil;
import com.example.restaurantclient.Entities.Dish;
import com.example.restaurantclient.R;

import java.util.List;

public class HotDishAdapter extends BaseAdapter {
    private List<Dish> dishes;
    private Context context;
    private int layoutItemId;
    public HotDishAdapter(Context context,List<Dish> dishes,int layoutItemId){
        this.dishes=dishes;
        this.context=context;
        this.layoutItemId=layoutItemId;
    }
    @Override
    public int getCount() {
        return dishes.size();
    }

    @Override
    public Object getItem(int position) {
        return dishes.get(position);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }


    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder=null;
        if (view==null){
            view= LayoutInflater.from(context).inflate(layoutItemId,
                    null);
            holder=new Holder();
            holder.tvDishName=view.findViewById(R.id.tv_dish_name);
            holder.tvDishPrice=view.findViewById(R.id.tv_dish_price);
            holder.tvDishComment=view.findViewById(R.id.tv_item_comment);
            holder.ivDishImg=view.findViewById(R.id.iv_item_img);
            view.setTag(holder);
        }else{
            holder= (Holder) view.getTag();
        }
        Dish dish=dishes.get(i);
        holder.tvDishName.setText(dish.getDishName());
        holder.tvDishPrice.setText(dish.getDishPrice()+"");
        holder.tvDishComment.setText(dish.getMainComment());

        holder.ivDishImg.setImageResource(context.getResources()
                .getIdentifier(dish.getDishImg(),"drawable",context.getPackageName()));
        return view;
    }
    class Holder{
        TextView tvDishName;
        TextView tvDishPrice;
        CircleImageUtil ivDishImg;
        TextView tvDishComment;

    }
}
